//
// Created by 123 on 2025/1/3.
//
#include "iostream"
using namespace std;

class CPU{
public:
    virtual void calculate() = 0;
};

class VESHOW{
public:
    virtual void display() = 0;
};

class MEM{
public:
    virtual void storage() = 0;
};

class Computer{
private:
    CPU* cpu;
    VESHOW* veshow;
    MEM* mem;
public:
    Computer(CPU* cpu,VESHOW* veshow,MEM* mem){
        this->cpu = cpu;
        this->veshow = veshow;
        this->mem = mem;
    }
    void work(){
        this->cpu->calculate();
        this->veshow->display();
        this->mem->storage();
    }
    ~Computer(){
        if(this->cpu != NULL){
            delete cpu;
            cpu = NULL;
        }
        if(this->veshow != NULL){
            delete veshow;
            veshow = NULL;
        }
        if(this->mem != NULL){
            delete mem;
            mem = NULL;
        }
    }
};

//============================
class IntelCPU : public CPU{
public:
    virtual void calculate(){
        cout << "intel cpu working" << endl;
    }
};
class IntelVESHOW : public VESHOW{
public:
    virtual void display(){
        cout << "intel veshow working" << endl;
    }
};
class IntelMEM : public MEM{
public:
    virtual void storage(){
        cout << "intel mem working" << endl;
    }
};

class AMDCPU : public CPU{
public:
    virtual void calculate(){
        cout << "amd cpu working" << endl;
    }
};
class AMDVESHOW : public VESHOW{
public:
    virtual void display(){
        cout << "amd veshow working" << endl;
    }
};
class AMDlMEM : public MEM{
public:
    virtual void storage(){
        cout << "amd mem working" << endl;
    }
};

void test01(){
    //配3台电脑
    CPU* intelCpu = new IntelCPU;
    VESHOW* intelVeshow = new IntelVESHOW;
    MEM* intelMem = new IntelMEM;
    Computer* com1 = new Computer(intelCpu,intelVeshow,intelMem);
    com1->work();
    delete com1;

    CPU* amdCPU = new AMDCPU;
    VESHOW* amdVeshow = new AMDVESHOW;
    MEM* amdMem = new AMDlMEM;
    Computer* com2 = new Computer(amdCPU,amdVeshow,amdMem);
    com2->work();
    delete com2;

    Computer* com3 = new Computer(new AMDCPU,new IntelVESHOW,new AMDlMEM);
    com3->work();
    delete com3;

}


int main092(){
    test01();

    return 0;
}